<html>
<head>
    <meta charset="utf-8">
    <title>轮播图编辑</title>
    <#assign base=request.contextPath  />
    <#setting  number_format="0.##"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${base}/backstage/layui/css/layui.css" media="all">
    <script src="${base}/sweep/js/mui.min.js"></script>
    <script src="${base}/backstage/layui/layui.js"></script>
    <script src="${base}/backstage/wangEdit/wangEditor.js"></script>
    <script src="${base}/backstage/js/jquery-1.8.3.min.js"></script>
    <script>
        var base =  "${base}";
    </script>
    <script src="${base}/backstage/js/ipNameUrl.js"></script>
</head>
<body>
<form class="layui-form " action="" style="padding-left: 15px;">
    <input type="hidden" value="${wheelPlanting.id}" id="id"/>
<br>
<br>
    <div class="layui-form-item">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">
            <div class="layui-upload-drag" id="test10">
                <div id="file1Div">
                    <img src="${wheelPlanting.url}" style="width: 342px;height: 136px">
                </div>
                <i class="layui-icon"></i>
                <p>点击下传，或将文件拖拽到此处</p>
            </div>
        </div>
    </div>
    <br>
    <br>
    <div class="layui-form-item">
        <label class="layui-form-label">内容</label>
        <div class="layui-input-block">
            <div id="content" style="height: 324px;width:730px;"></div>
        </div>
    </div>
<br>
<br>
<br>
    <div align="center">
        <button type="button" class="layui-btn" id="saveButton">保存</button>
        <button type="button" class="layui-btn" onclick="window.history.back(-1);">返回</button>
    </div>
    <br>
    <br>
</form>

</body>
<script>
    //复文本
    var E = window.wangEditor;
    var content = new E('#content');
    content.create();
    var text = content.txt.html(`${wheelPlanting.details}`);

    var param = "";
    layui.use(['form', 'layer', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , $ = layui.jquery
            , upload = layui.upload;

        //拖拽下传
        upload.render({
            elem: '#test10'
            , url: '${base}/admin/file/uploadFile'
            , before: function (obj) {
                layer.load(); //上传loading
            }
            , done: function (res) {
                layer.closeAll('loading'); //关闭loading
                //如果下传失败
                if (res.code > 0) {
                    return layer.msg('上传失败');
                }
                $("#file1Div").html("")
                $('#file1Div').append('><img src="' + res.data + '" style="width: 342px;height: 136px">'); //图片链接（base64）
                param += res.data;
                return layer.msg('上传成功');
            }
        });
    })

    $("#saveButton").on("click", function () {


        if (content.txt.html() == '<p><br></p>') {
            layer.msg("请填写内容！")
            return;
        }
        var formDate = {
            details: content.txt.html(),
            url: param,
            id: $("#id").val()
        }


        $.ajax({
            type: "POST",
            contentType: "application/json;charset=UTF-8",
            url: "${base}/admin/wheelPlanting/saveOrUpdateById",
            data: JSON.stringify(formDate),
            success: function (data) {
                if (data.code === 200) {
                    layer.msg(data.msg)
                    window.location.href = "${base}/admin/wheelPlanting/wheelPlanting.html"
                } else {
                    layer.msg(data.msg)
                }
            }
        });
    })
</script>
</html>


